<template>
	<view>
		<web-view @message="message" :src="linkUrl" v-if="linkUrl" class="web-box"></web-view>
	</view>
</template>

<script>
	import config from '@/common/config/config.js'
	import { lastVersion } from '@/common/api/api.js'
	export default {
		data() {
			return {
				linkUrl: '',
				config: config
			};
		},
		onLoad(e) {
			uni.showLoading({
				title: '加载中...'
			})
			// #ifdef H5
			window.addEventListener('message', this.message)
			// #endif
			// 清除应用缓存
			// // #ifdef APP-PLUS
			// plus.cache.clear()
			// // #endif
			this.linkUrl = this.config.env.tradeWeb + '?token=' + uni.getStorageSync('tradeToken') + '&tenantId=1'
			setTimeout(()=> {
				uni.hideLoading()
			},10000)
		},
		onShow() {
			this.getLastVersion()
		},
		methods: {
			message(e) {
				uni.hideLoading()
			},
			getLastVersion() {
				lastVersion(1).then(res => {
					if(res.code == 200) {
						this.versionInfo = res.data || {}
						// 清除webview缓存
						if(this.versionInfo.versionCode != uni.getStorageSync('ycwmVersion')) {
							uni.setStorageSync('ycwmVersion', this.versionInfo.versionCode)
							// #ifdef APP-PLUS
							plus.cache.clear()
							// #endif
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.web-box {
	height: calc(100vh - 88rpx);
}
</style>
